{extend name="admin/index"}


{block name="main"}
    <h2 class="sub-header">{$table}</h2>
    <div class="table-responsive">
        <table class="table table-striped table-hover">
            <thead>
                <tr>
                    <th>#</th>
                    <th>电影名</th>
                    <th>语言</th>
                    <th>类型</th>
                    <th>导演</th>
                    <th>时长</th>
                    <th>操作</th>
                </tr>
            </thead>
            <tbody>
            {foreach $list as $v}
                <tr>
                    <td>{$v.id}</td>
                    <td>{$v.filmname}</td>
                    <td>{$v.language}</td>
                    <td>{$v.type}</td>
                    <td>{$v.duration}</td>
                    <td>
                        {$v.release_time} 分钟
                    </td>
                    <td>
                        <a class='btn btn-primary btn-sm' href="{:url('admin/film/edit',['id'=>$v.id])}">编辑</a>
                        <a class='btn btn-info btn-sm dt-btn' href="{:url('admin/upload/index',['id'=>$v.id])}">图片</a>
                        <button class='btn btn-danger btn-sm del-btn' data-id="{$v.id}">删除</button>
                    </td>
                </tr>
            {/foreach}
                
            </tbody>
        </table>
    </div>
</div>

{/block}


{block name="js"}
<script>
  $(".filmlist").addClass('active');


    $('.del-btn').click(function(){
        var id = $(this).attr('data-id');
        if(confirm('确定要删除该影片吗?')){
            var obj = $(this).parents('tr');
            delajax(id, obj);
        }
    })

    // 删除操作
    function delajax(id, obj){
        $.ajax({
            type:'delete',
            url: '/adfilm/'+id,
            dataType:'json',
            success:function(data){
              if (data.status) {
                    toastr.success(data.info);
                    obj.remove();
                } else {
                    toastr.error(data.info,'FBI WARNING: ');
                }
            },
            error:function(){
                alert('ajax执行失败');
            }
        })
    }

    // 电影详情


</script>
{/block}